import * as echarts from 'echarts';
import type { ChartStrategy } from './useECharts';

// 定义图表配置项的接口
export interface EChartOption {
   backgroundColor?: string;
   title?: echarts.EChartsOption['title'];
   tooltip?: echarts.EChartsOption['tooltip'];
   grid?: echarts.EChartsOption['grid'];
   legend?: echarts.EChartsOption['legend'];
   xAxis?: echarts.EChartsOption['xAxis'];
   yAxis?: echarts.EChartsOption['yAxis'];
   series?: echarts.EChartsOption['series'];
}

// 通用图表配置项构造函数
export class EChartOptionBuilder {
   private option: EChartOption = {};
   setBackgroundColor(backgroundColor: string): this {
      this.option.backgroundColor = backgroundColor;
      return this;
   }
   setTitle(title: EChartOption['title']): this {
      this.option.title = title;
      return this;
   }

   setTooltip(tooltip: EChartOption['tooltip']): this {
      this.option.tooltip = tooltip;
      return this;
   }

   setGrid(grid: EChartOption['grid']): this {
      this.option.grid = grid;
      return this;
   }

   setLegend(legend: EChartOption['legend']): this {
      this.option.legend = legend;
      return this;
   }

   setXAxis(xAxis: EChartOption['xAxis']): this {
      this.option.xAxis = xAxis;
      return this;
   }

   setYAxis(yAxis: EChartOption['yAxis']): this {
      this.option.yAxis = yAxis;
      return this;
   }

   addSeries(series: EChartOption['series']): this {
      if (!this.option.series) {
         this.option.series = [];
      }
      this.option.series = series;
      return this;
   }

   build(): EChartOption {
      return this.option;
   }
}

export class GanttChart implements ChartStrategy {
   getOptions: () => echarts.EChartsOption; // 声明getOptions属性
   constructor(newOptions: any) {
      this.getOptions = () => newOptions;
   }
}
